package itheima.com.Day12;

import java.io.*;
import java.util.ArrayList;

public class ConvertedDemo6 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Actor a1 = new Actor("糖果超甜", 26);
        Actor a2 = new Actor("甜心派对", 25);
        Actor a3 = new Actor("咸蛋超人", 27);

        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("Master\\c.txt"));

        ArrayList<Actor> list1 = new ArrayList<>();
        list1.add(a1);
        list1.add(a2);
        list1.add(a3);
        oos.writeObject(list1);

        oos.close();
             /*  oos.writeObject(a1);
        oos.writeObject(a2);
        oos.writeObject(a3);*/


        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("Master\\c.txt"));
        ArrayList<Actor> list2 = (ArrayList<Actor>)ois.readObject();
        for (Actor actor : list2) {
            System.out.println(actor);
        }
        ois.close();
         /* while ((obj=ois.readObject())!=null){
            System.out.println(obj);
        } // 有异常(EXOEXCEPTION)需要抛出*/

       /* while (true){
            try {
                Object o = ois.readObject();
                System.out.println(o);
            } catch (IOException e) {
                break;
            }
        }*/
    }
}
